package com.suyin.ximoon.shiro.filter;

import javax.annotation.Resource;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.web.filter.PathMatchingFilter;

import com.suyin.ximoon.plugin.mybatis.Criteria;
import com.suyin.ximoon.plugin.mybatis.Restriction;
import com.suyin.ximoon.service.LyUserService;



public class SysUserFilter extends PathMatchingFilter {

	@Resource
	private LyUserService lyUserService;

    @Override
    protected boolean onPreHandle(ServletRequest request, ServletResponse response, Object mappedValue) throws Exception {
        String username = (String)SecurityUtils.getSubject().getPrincipal();
        Criteria criteria = new Criteria();
        criteria.add(Restriction.eq("accountName", username));
        request.setAttribute("user", lyUserService.query(criteria));
        return true;
    }
}